<?php namespace Admin\Controller; 
/**
 * 友情链接控制器
 */
class LinkController extends CommonController{
		private $link = null;
		public function __init(){
				parent::__init();
				$this->link = new \Common\Model\Link();
		}
		
		//显示页
		public function index(){
				$page = Page::row(8)->make($this->link->count());
				$linkData = $this->link->limit(Page::limit())->get();
				$this->assign('page',$page);
				$this->assign('total',$this->link->count());
				$this->assign('linkData',$linkData);
			 	$this->display();
		}
		
		//添加
		public function  add(){
				if (IS_POST) {
					 if ($this->link->store()) {
					 		$this->success('添加成功,马上为您跳转...',U('index'));
					 }
					 $this->error($this->link->getError());
				}
				$this->display();
		}
		
		//修改
		public function  edit(){
				if (IS_POST) {
						if ($this->link->edit(Q('post.lid',0,'intval'))) {
							 $this->success('编辑成功,马上为您跳转...',U('index'));
						}
						$this->error($this->link->getError());
				}
				//查出旧数据,并分配
				$lid = Q('get.lid',0,'intval');
				$this->assign('oldData',$this->link->where(array('lid' => $lid))->find());
				$this->display();
		}
		
		//删除
		public function  del(){
				if ($this->link->del(Q('lid',0,'intval'))) $this->success('删除成功',U('index'));
		}
}